/**
 * 
 */
package com.gragra.nounIdentification;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import com.gragra.data.Corpus;
import com.gragra.sampling.sequentialStructure.ExtensionInformationHolder;
import com.gragra.sampling.sequentialStructure.ExtensionLevels;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.util.IntPairSet;
/**
 * @author Christoph Teichmann
 * 31.07.2013
 */
public class CountIdentifier extends ExtendingNounIdentifier
{
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#extendNouns(com.gragra.data.Corpus)
	 */
	@Override
	protected void extendNouns(Corpus<WordAndTagHolder> data)
	{
		pairs = new IntPairSet();
		super.extendNouns(data);
	}
	/**
	 * 
	 */
	private IntPairSet pairs;
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#evaluate(com.gragra.data.Corpus, boolean)
	 */
	@Override
	public double[] evaluate(Corpus<WordAndTagHolder> data, boolean microAverage)
	{
		pairs = new IntPairSet();
		return super.evaluate(data, microAverage);
	}
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#annotateCorpusFrames(com.gragra.data.Corpus)
	 */
	@Override
	public void annotateCorpusFrames(Corpus<WordAndTagHolder> data)
	{this.extendNouns(data);}
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#annotateCorpusWords(com.gragra.data.Corpus)
	 */
	@Override
	public void annotateCorpusWords(Corpus<WordAndTagHolder> data)
	{this.extendNouns(data);}
	/**
	 * 
	 * @param data
	 * @param frameSize
	 * @param preMarkers
	 * @param postMarkers
	 * @param sco
	 * @param ca
	 * @param ma
	 * @param minCount
	 */
	public CountIdentifier(Corpus<WordAndTagHolder> data, int frameSize,
			int preMarkers, int postMarkers, Scorer sco,
			ConvergenceAssessment ca, MaxAssessment ma, int numberOfTagsUsed)
	{
		super(data, frameSize, preMarkers, postMarkers, sco, ca, ma, numberOfTagsUsed);
	}
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#increaseCount(com.gragra.sampling.sequentialStructure.WordAndTagHolder, com.gragra.sampling.sequentialStructure.ExtensionInformationHolder, int)
	 */
	@Override
	protected void increaseCount(WordAndTagHolder wth,
			ExtensionInformationHolder eih, int position)
	{
		int tag;
		if((tag = eih.getInfiniteInformation(position, ExtensionLevels.ContextTagLevel)) >= 0 && pairs.add(tag, wth.getWord(position)))
		{super.getCounts().addTo(tag, 1);}
	}
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#decideTypePresent(com.gragra.sampling.sequentialStructure.WordAndTagHolder, int)
	 */
	@Override
	protected boolean decideTypePresent(WordAndTagHolder wth, int j)
	{
		int tag;
		return ((tag = wth.getExtensionInformation().getInfiniteInformation(j, ExtensionLevels.ContextTagLevel)) >= 0 && this.getCounts().containsKey(tag));
	}
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#testForAdding(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap, com.gragra.sampling.sequentialStructure.WordAndTagHolder, com.gragra.sampling.sequentialStructure.ExtensionInformationHolder, int)
	 */
	@Override
	protected boolean testForAdding(Int2IntOpenHashMap map,
			WordAndTagHolder wth, ExtensionInformationHolder eih, int i)
	{
		int tag;
		return ((tag = wth.getExtensionInformation().getInfiniteInformation(i, ExtensionLevels.ContextTagLevel)) >= 0 && map.containsKey(tag));
	}
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ExtendingNounIdentifier#extendMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap, com.gragra.sampling.sequentialStructure.ExtensionInformationHolder, int)
	 */
	@Override
	protected void extendMap(Int2IntOpenHashMap map,
			ExtensionInformationHolder eih, int i, WordAndTagHolder wth)
	{
		int tag;
		if((tag = eih.getInfiniteInformation(i, ExtensionLevels.ContextTagLevel)) >=  0 && pairs.add(tag, wth.getWord(i)))
		{map.addTo(tag, 1);}
	}
}